﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.门店下单.service;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.客户管理
{
    public partial class Form客户一览 : DevExpress.XtraEditors.XtraForm
    {
        private String shopId;
        private DTO选择用户 DTO选择用户;
        public CustomerChooseInfoDTO customerChooseInfoDTO;
        public Form客户一览()
        {
            InitializeComponent();
        }
        public Form客户一览(String shopId, DTO选择用户 DTO选择用户, CustomerChooseInfoDTO customerChooseInfoDTO)
        {
            InitializeComponent();
            this.shopId = shopId;
            this.DTO选择用户 = DTO选择用户;
            this.customerChooseInfoDTO = customerChooseInfoDTO;
        }
        private void Form客户一览_Load(object sender, EventArgs e)
        {
            this.splashScreenManager.ShowWaitForm();
            this.splashScreenManager.SetWaitFormCaption("请稍后,正在加载中....");     // 标题
            this.splashScreenManager.SetWaitFormDescription("正在初始化.....");     // 信息
            //this.gridControl客户一览.DataSource = CustomerService.GetCustomers(this.shopId);
            List<ViewCustomerDTO> viewCustomerDTOs = new List<ViewCustomerDTO>();
            viewCustomerDTOs = CustomerService.GetViewCustomerDTOs18();
            this.gridControl客户一览.DataSource = viewCustomerDTOs;
            this.splashScreenManager.CloseWaitForm();
        }

        private void gridView客户一览_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            this.DTO选择用户.customerId = FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "customerId");
            this.DTO选择用户.addressId = FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "addressId");
            this.DTO选择用户.customerCountId = FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "customerFitId");
            this.DTO选择用户.customerName = FunctionHelper.GetgridViewValue(this.gridView客户一览, e.RowHandle, "customerFitName");
            this.DTO选择用户.shopId = this.shopId;
            if (String.IsNullOrWhiteSpace(this.DTO选择用户.addressId))
            {
                MessageBox.Show("客户未创建地址");
            }
            else if (String.IsNullOrWhiteSpace(this.DTO选择用户.customerCountId))
            {
                MessageBox.Show("客户未创建量体");
            }
            else
            {
                this.customerChooseInfoDTO = FunctionHelper.JsonDeserialization<CustomerChooseInfoDTO>(RestCall.httpGetMethod(URL.接口url + "/order/commonCustomerChoice/getCustomerChooseInfoDTOById" +
                "?customerId=" + this.DTO选择用户.customerId +
                "&addressId=" + this.DTO选择用户.addressId +
                "&countId=" + this.DTO选择用户.customerCountId));

                this.Close();
            }
        }
    }
}
